package com.dp.util;

import java.sql.Time;
import java.sql.Timestamp;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class TimeStamp {

	public static int transSequence=0;
    static Object object=new Object();
	
	public static int getTransSequence(){
        synchronized (object){
			if(TimeStamp.transSequence==9999)
				TimeStamp.transSequence=0;
			TimeStamp.transSequence++;
			return TimeStamp.transSequence;
        }
	}
	public static String getStringTransSequence(){
		int timestamp = getTransSequence();
		String str=String.valueOf(timestamp);
		int m=str.length();
		String str0="";
		for(int i=0;i<4-m;i++)
			str0+="0";
		str=str0+str;
		return str;
	}	
	public static int getIntTimestamp(){
		Calendar calendar = new GregorianCalendar();
		Date trialTime = new Date();
		calendar.setTime(trialTime);
		int month = calendar.get(Calendar.MONTH)+1;		
		int date = calendar.get(Calendar.DATE);		
		//int hour = calendar.get(Calendar.HOUR);//12h
		int hour = calendar.get(Calendar.HOUR_OF_DAY);//24h
		int minute = calendar.get(Calendar.MINUTE);
		int second = calendar.get(Calendar.SECOND);
		int timestamp = month*100000000+date*1000000
						+hour*10000+minute*100+second;
		return timestamp;
	}
	
	public static String getStringTimestamp(){
		int timestamp = getIntTimestamp();
		return timestamp<1000000000 ?
				"0"+String.valueOf(timestamp) : String.valueOf(timestamp);
		
	}
	
	public static int getIntTimeyear(){
		Calendar calendar = new GregorianCalendar();
		Date trialTime = new Date();
		calendar.setTime(trialTime);
		int year = calendar.get(Calendar.YEAR);

		int timeyear = year;
		return timeyear;
	}
	
	public static String getStringTimeyear(){
		int timeyear = getIntTimeyear();
		return String.valueOf(timeyear);
	}

	public static String getSequence(){
		
		return getStringTimeyear()+getStringTimestamp()+getStringTransSequence();
	}
	
	
	public static long getNow() {
	   return System.currentTimeMillis();
	}
	
	  /**
	   * @return String
	   */
	  public String getTransactionID() {

	    long ct = System.currentTimeMillis();

	    return (ct - 1124603018562L) + "";

	  }


	  
	  public Timestamp getNowTime() {

	    return new Timestamp(System.currentTimeMillis());

	  }

	  /**
	   * ��������
	   * @return Date
	   */
	  public java.sql.Date getToday() {

	    return new java.sql.Date(System.currentTimeMillis());

	  }

	  /**
	   * ����ʱ��
	   * @return Date
	   */
	  public Time getTime() {

	    return new Time(System.currentTimeMillis());

	  }

	  public Timestamp getAfterTime(long t) {
	    return new Timestamp(System.currentTimeMillis() + t * 60 * 1000);
	  }

	  public Timestamp getBeforeTime(long t) {
	    return new Timestamp(System.currentTimeMillis() - t * 60 * 1000);
	  }
	  public Timestamp getBeforeDate(long t) {
	    return new Timestamp(System.currentTimeMillis() - t * 24 * 60 * 60 * 1000);
	  }
	  public static void main(String[] args) {
		  System.out.println(getSequence());
		  
	  }

}
